#include "mainmenu.h"
#include "ui_mainmenu.h"
#include <QPainter>
MainMenu::MainMenu(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::MainMenu)
{
    ui->setupUi(this);
    pix.load(MENU_BG);
    this->initScene(); //初始化窗口
    play = new QSound(GAME_BGM_GAME_MENU);
    play->play();

    pix5.load(MENU_PIX5);
}

MainMenu::~MainMenu()
{
    delete ui;
}

//点击闯关按钮
void MainMenu::on_chuangGuan_clicked()
{
    this->mainWidget->isChuangGuanOrWujin = true; //置为闯关模式
    emit sendScore(this->mainWidget->score); //发送分数给关卡选择窗口
    this->play->stop();
    this->hide(); //隐藏当前窗口
    this->gqc->show(); //显示关卡选择窗口
    this->gqc->play->play();
}

//点击无尽按钮
void MainMenu::on_wuJin_clicked()
{

    play->stop();

    this->mainWidget->isChuangGuanOrWujin = false;

    this->hide(); //隐藏当前窗口
    emit this->sendMoShi(); //发送模式选择完成信号
    this->mainWidget->score = 0;
    this->mainWidget->show(); //显示主窗口
    //this->mainWidget->playGame();
}

//点击退出按钮
void MainMenu::on_exit_clicked()
{
    QApplication::exit(); //退出
}


void MainMenu::on_about_clicked()
{
    QMessageBox::about(this, "关于彩色连珠", ABOUT);
}

//初始化窗口
void MainMenu::initScene(){
    this->mainWidget = new Widget;
    this->gqc = new guanQiaChoose(mainWidget);
    setWindowTitle(GAME_NAME);
    setFixedSize(731,1000);
        ui->chuangGuan->setIconSize(QSize(150,50));
        ui->chuangGuan->setIcon(QIcon(MENU_PIX1));
        ui->chuangGuan->setStyleSheet("QPushButton{background-color:rgba(0,0,0,0);}");
        ui->wuJin->setIconSize(QSize(150,50));
        ui->wuJin->setIcon(QIcon(MENU_PIX2));
       ui->wuJin->setStyleSheet("QPushButton{background-color:rgba(0,0,0,0);}");
        ui->exit->setIconSize(QSize(150,50));
        ui->exit->setIcon(QIcon(MENU_PIX3));
        ui->exit->setStyleSheet("QPushButton{background-color:rgba(0,0,0,0);}");
        ui->about->setIconSize(QSize(150,50));
        ui->about->setIcon(QIcon(MENU_PIX4));
        ui->about->setStyleSheet("QPushButton{background-color:rgba(0,0,0,0);}");
        setWindowIcon(QIcon(GAME_ICON_));


    setWindowIcon(QIcon(GAME_ICON_));
}

void MainMenu::showMainMenu(){
    this->play->play();
    this->show(); //显示主菜单
}

void MainMenu:: paintEvent(QPaintEvent * event){
    QPainter painter(this);

    painter.drawPixmap(0,0,pix);
    painter.drawPixmap(190,135,pix5);

}
